#ifndef DBWRITER_H
#define DBWRITER_H
#include <QVector>
#include <QString>
#include <QSqlQuery>
#include <QSqlField>

#define POLYGON_TABLE_NAME "Polygon"
#define EMF_TABLE_NAME "Emf"
#define LOOP_TABLE_NAME "GeneratorLoop"
#define PICKET_TABLE_NAME "Picket"
#define MEASUREMENT_TYPE_COAXIAL 1


struct SimpleRecord
{
    virtual QString createInsertSql()=0;
    virtual QString createGetMaxIdSql()=0;
    virtual ~SimpleRecord() {}
};

struct BulkInsertRecord
{
    virtual QString createValuesSql()=0;
    virtual QString createInsertSqlPrefix()=0;

    virtual ~BulkInsertRecord() {}
};



struct PolygonRecord : public SimpleRecord
{
public:
    QString description;
    int idMeasurementType;

public:
    virtual QString createInsertSql();
    virtual QString createGetMaxIdSql();
};

struct EmfRecord : public BulkInsertRecord
{
public:
    int idEmf;
    double time;
    double value;

public:
    virtual QString createValuesSql();
    virtual QString createInsertSqlPrefix();

    int createId();
};

struct PicketRecord : public BulkInsertRecord, public SimpleRecord
{
public:
    int idGeneratorLoop;
    int idEmf;
    double x;
    double y;
    double z;
    double height;

public:
    virtual QString createValuesSql();
    virtual QString createInsertSqlPrefix();
    virtual QString createInsertSql();
    virtual QString createGetMaxIdSql();

};

struct LoopReecord : public SimpleRecord
{
public:
    int idPolygon;
    int idLoopForm;
    double turnAngle;
    double size;
    double current;
    int turnsNumber;
    int centerX;
    int centerY;

public:
    virtual QString createInsertSql();
    virtual QString createGetMaxIdSql();
};


class DbWriter
{
private:
    int _getLastInsertedId(QSqlQuery &lastQuery, SimpleRecord *record);

public:
    DbWriter();

    int addSingleRecord(SimpleRecord* record);
    bool addMultipleRecords(QVector<BulkInsertRecord *> &values);

};

#endif // DBWRITER_H
